package com.example.common.utils;

import com.example.common.model.ResultObj;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**
 * @Author: lex
 * @Date: 2018/11/14
 */
public abstract class ValidatedUtils {

    public static ResultObj errorResultMsg(BindingResult result) {
        FieldError fieldError = result.getFieldError();
        if (fieldError==null) {
            return null;
        }
        String field=fieldError.getField();
        String defaultMessage=fieldError.getDefaultMessage();
        return new ResultObj(407,"错误字段: "+field +" 错误原因: "+ defaultMessage);
    }
}
